﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SalePartial.IDAL;
using System.Data.SqlClient;
using SalePartial.Model;

namespace SalePartial.BLL
{
    public class XPCompany : IXPCompany
    {
        private IXPCompany dal = SalePartial.DALFactory.DataAccess.CreateXPCompany();

        //public void Create()
        //{
        //    XPCompanyUtility.Insert(this.CompanyID, this.UserID, this.CompanyName, this.CompanyAliasName, this.Industry, this.WebSite, this.OfficePhone, this.OfficePhoneValidate, this.IsOfficePhonePublic, this.CellPhone,
        //    this.CellPhoneValidate, this.IsCellPhonePublic, this.Fax, this.FaxValidate, this.IsFaxPublic, this.Country, this.Province, this.City, this.Address, this.PostCode,
        //    this.CompanyOwner, this.CompanyContact, this.CompanyEmail, this.IsEmailPublic, this.LicenseCertID, this.Photo, this.Logo, this.Description, this.Monetary, this.Scale,
        //    this.Fund, this.Software, this.Technology, this.Product, this.CreateDate, this.IsApproved, this.IsLockedOut, this.VendorModerateDate, this.VendorModerateUser, this.VendorModerateStatus,
        //    this.BuyerModerateDate, this.BuyerModerateUser, this.BuyerModerateStatus, this.LastModerateDate, this.ModerateUser, this.ModerateCount, this.ModerateComment);
        //}

        //public int CreateNew()
        //{
        //    return XPCompanyUtility.Insert(this.CompanyID, this.UserID, this.CompanyName, this.CompanyAliasName, this.Industry, this.WebSite, this.OfficePhone, this.OfficePhoneValidate, this.IsOfficePhonePublic, this.CellPhone,
        //    this.CellPhoneValidate, this.IsCellPhonePublic, this.Fax, this.FaxValidate, this.IsFaxPublic, this.Country, this.Province, this.City, this.Address, this.PostCode,
        //    this.CompanyOwner, this.CompanyContact, this.CompanyEmail, this.IsEmailPublic, this.LicenseCertID, this.Photo, this.Logo, this.Description, this.Monetary, this.Scale,
        //    this.Fund, this.Software, this.Technology, this.Product, this.CreateDate, this.IsApproved, this.IsLockedOut, this.VendorModerateDate, this.VendorModerateUser, this.VendorModerateStatus,
        //    this.BuyerModerateDate, this.BuyerModerateUser, this.BuyerModerateStatus, this.LastModerateDate, this.ModerateUser, this.ModerateCount, this.ModerateComment);
        //}

        public void Delete(XPCompanyInfo companyInfo)
        {
            dal.Delete(companyInfo.CompanyID);
        }

        public  XPCompanyInfo GetXPCompany(Guid id)
        {
            SqlDataReader reader = this.SelectReader(id);
            if (reader.Read())
            {
                XPCompanyInfo info = new XPCompanyInfo(reader);
                if (!reader.IsClosed)
                {
                    reader.Close();
                }
            
                return info;
            }
            return null;

        }

        //public void Update()
        //{
        //    XPCompanyUtility.Update(this.CompanyID, this.UserID, this.CompanyName, this.CompanyAliasName, this.Industry, this.WebSite, this.OfficePhone, this.OfficePhoneValidate, this.IsOfficePhonePublic, this.CellPhone,
        //    this.CellPhoneValidate, this.IsCellPhonePublic, this.Fax, this.FaxValidate, this.IsFaxPublic, this.Country, this.Province, this.City, this.Address, this.PostCode,
        //    this.CompanyOwner, this.CompanyContact, this.CompanyEmail, this.IsEmailPublic, this.LicenseCertID, this.Photo, this.Logo, this.Description, this.Monetary, this.Scale,
        //    this.Fund, this.Software, this.Technology, this.Product, this.CreateDate, this.IsApproved, this.IsLockedOut, this.VendorModerateDate, this.VendorModerateUser, this.VendorModerateStatus,
        //    this.BuyerModerateDate, this.BuyerModerateUser, this.BuyerModerateStatus, this.LastModerateDate, this.ModerateUser, this.ModerateCount, this.ModerateComment);
        //}

        public int Delete(Guid CompanyID)
        {
            return dal.Delete(CompanyID);
        }

        public int DeleteByUserID(Guid UserID)
        {
            return dal.DeleteByUserID(UserID);
        }

        public int DeleteDynamic(string v_whereCondition)
        {
            return dal.DeleteDynamic(v_whereCondition);
        }

        public int Insert(XPCompanyInfo info)
        {
            return dal.Insert(info);
        }

        public System.Data.DataSet SelectAll()
        {
            return dal.SelectAll();
        }

        public System.Data.DataSet SelectByUserID(Guid UserID)
        {
            return dal.SelectByUserID(UserID);
        }

        public List<XPCompanyInfo> SelectInfoByUserID(Guid UserID)
        {
            SqlDataReader reader = this.SelectReaderByUserID(UserID);
            List<XPCompanyInfo> infoList = new List<XPCompanyInfo>();
            while (reader.Read())
            {
                XPCompanyInfo info = new XPCompanyInfo(reader);
                infoList.Add(info);
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return infoList;
        }

        public System.Data.DataSet SelectDynamic(string v_whereCondition, string v_orderByExpression)
        {
            return dal.SelectDynamic(v_whereCondition, v_orderByExpression);
        }

        public System.Data.DataSet SelectPaged()
        {
            return dal.SelectPaged();
        }

        public System.Data.SqlClient.SqlDataReader SelectReader(Guid CompanyID)
        {
            return dal.SelectReader(CompanyID);
        }

        public System.Data.SqlClient.SqlDataReader SelectReaderByUserID(Guid UserID)
        {
            return dal.SelectReaderByUserID(UserID);
        }

        public System.Data.DataSet SelectSingle(Guid CompanyID)
        {
            return dal.SelectSingle(CompanyID);
        }

        public int Update(XPCompanyInfo info)
        {
            return dal.Update(info);
        }
    }

}
